import HTMLParser
import urllib
import re
import string


urlString = "http://www.jpix.ad.jp/en/user/osaka.html"
urlText = []
pathOut = "ixp_members.txt"


class Parse164 (HTMLParser.HTMLParser):
    
    check = False
    
    def handle_starttag (self, tag, attrs):
        if tag == "td":
            self.check = True
    
    def handle_data (self, data):
        if self.check == True and re.match("^AS\d+$",data):
            data = string.lstrip(data, "AS")
            if data not in urlText:
                urlText.append(data)
        self.check = False


lparser = Parse164()
lparser.feed(urllib.urlopen(urlString).read())
fileOut = open(pathOut, "a")
for item in urlText:
    #print item # debug
    print >> fileOut, "164 %s" % item
fileOut.close()